## traditional MM Likert outcome using only white respondents
##
## August 5, 2019
##
## Kevin Quinn
## University of Michigan
##

library(MCMCpack)
set.seed(5627)

mydata <- read.csv("../ScaleRaceSpring2017clean.csv")

## subset data
mydata <- mydata[mydata$R.race == "White",]
mydata <- mydata[!is.na(mydata$R.race),]


## keep responses and photo IDs but nothing else
inds <- 1:24
keep.vars <- c(paste("X", inds, "_Q339", sep=""),
               paste("X", inds, "a.id", sep=""))

mydata.sub <- mydata[, keep.vars]


## reshape into long format
mydata.sub.long <- reshape(mydata.sub, direction="long",
                           varying=list(c(1:24), c(25:48)),
                           v.names=c("Y", "photoID"),
                           ids=rownames(mydata.sub))

## keep only obs with non-missing values for MM
mydata.sub.long <- na.omit(mydata.sub.long)

mydata.sub.long <- mydata.sub.long[sample(1:nrow(mydata.sub.long),
                                          size=1000, replace=FALSE),]

cat("\n\nN =", nrow(mydata.sub.long), "\n\n") 


b3.M1.out <- MCMCoprobit(Y ~ as.factor(photoID), data=mydata.sub.long,
                         burnin=50000, mcmc=1000000, thin=50, tune=0.06,
                         verbose=10000, seed=81571
                         )


save(b3.M1.out, file="MM3.2.b3.M1.out.Rda")
